package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbavo.VoyageBsaCbaCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbavo.VoyageBsaCbaPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbavo.VoyageBsaCbaQuantityVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbavo.VoyageBsaCbaRespVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbavo.VoyageBsaCbaUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmc.cloud.cmclink.doc.entity.VoyageBsaCbaDO;
import com.cmc.cloud.cmclink.doc.service.VoyageBsaCbaService;


/**
 * Class-based Allocation分类舱位前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - Class-based Allocation分类舱位")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/bsaCba")
public class VoyageBsaCbaController {

    @Resource
    private VoyageBsaCbaService voyageBsaCbaService;

    @Operation(summary = "创建Class-based Allocation分类舱位")
    @PostMapping("/create")
    public CommonResult<Void> createVoyageBsaCba(@Valid @RequestBody VoyageBsaCbaCreateReqVO createReqVO) {
        voyageBsaCbaService.createVoyageBsaCba(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新Class-based Allocation分类舱位")
    @PostMapping("/update")
    public CommonResult<Void> updateVoyageBsaCba(@Valid @RequestBody VoyageBsaCbaUpdateReqVO updateReqVO) {
        voyageBsaCbaService.updateVoyageBsaCba(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "操作Class-based Allocation分类舱位 数量")
    @PostMapping("/operateSpaceNum")
    public CommonResult<Void> operateBsaSpaceNum(@Valid @RequestBody VoyageBsaCbaQuantityVO bsaCbaQuantityVO) {
        voyageBsaCbaService.operateBsaSpaceNum(bsaCbaQuantityVO);
        return CommonResult.success();
    };

    @Operation(summary = "删除Class-based Allocation分类舱位")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteVoyageBsaCba(@PathVariable("id") Long id) {
        voyageBsaCbaService.deleteVoyageBsaCba(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得Class-based Allocation分类舱位")
    @GetMapping("/getById/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<VoyageBsaCbaRespVO> getVoyageBsaCba(@PathVariable("id") Long id) {
        VoyageBsaCbaDO voyageBsaCba = voyageBsaCbaService.getVoyageBsaCba(id);
        return CommonResult.success(BeanUtil.copyProperties(voyageBsaCba, VoyageBsaCbaRespVO.class));
    }

    @Operation(summary = "根据主信息id获取分类舱位")
    @GetMapping("/getByMainId")
    @Parameter(name = "voyageBsaId", description = "编号", required = true, example = "1024")
    @Parameter(name = "spaceTypeCode", description = "舱位类型代码", required = true, example = "Reserve Space")
    public CommonResult<List<VoyageBsaCbaRespVO>> getByMainId(@RequestParam("voyageBsaId") Long voyageBsaId, @RequestParam("spaceTypeCode") String spaceTypeCode) {
        return CommonResult.success(voyageBsaCbaService.getByMainId(voyageBsaId, spaceTypeCode));
    }

    @Operation(summary = "获得Class-based Allocation分类舱位列表")
    @GetMapping("/listAll")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<VoyageBsaCbaRespVO>> getVoyageBsaCbaList(@RequestParam("ids") Collection<Long> ids) {
        List<VoyageBsaCbaDO> list = voyageBsaCbaService.getVoyageBsaCbaList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, VoyageBsaCbaRespVO.class));
    }

    @Operation(summary = "获得Class-based Allocation分类舱位分页")
    @GetMapping("/page")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<VoyageBsaCbaRespVO>> getVoyageBsaCbaPage(@Valid @RequestBody VoyageBsaCbaPageReqVO pageVO) {
        PageResult<VoyageBsaCbaDO> pageResult = voyageBsaCbaService.getVoyageBsaCbaPage(pageVO);
        List<VoyageBsaCbaRespVO> results = BeanUtil.copyToList(pageResult.getList(), VoyageBsaCbaRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
